





<!DOCTYPE html>
<html class="writer-html5" lang="zh-CN" >
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>语言参考 &mdash; tvm 0.8.dev1982 文档</title>
  

  
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/gallery.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/tlcpack_theme.css" type="text/css" />

  
  
    <link rel="shortcut icon" href="../../_static/tvm-logo-square.png"/>
  

  
  
  
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
        <script src="../../_static/jquery.js"></script>
        <script src="../../_static/underscore.js"></script>
        <script src="../../_static/doctools.js"></script>
        <script src="../../_static/translations.js"></script>
    
    <script type="text/javascript" src="../../_static/js/theme.js"></script>

    
    <script type="text/javascript" src="../../_static/js/tlcpack_theme.js"></script>
    <link rel="index" title="索引" href="../../genindex.html" />
    <link rel="search" title="搜索" href="../../search.html" />
    <link rel="next" title="Expressions in Relay" href="relay_expr.html" />
    <link rel="prev" title="Auto-tuning a convolutional network on VTA" href="../../topic/vta/tutorials/autotvm/tune_relay_vta.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    
<header class="header">
    <div class="innercontainer">
      <div class="headerInner d-flex justify-content-between align-items-center">
          <div class="headerLogo">
               <a href="https://tvm.apache.org/"><img src=https://tvm.apache.org/assets/images/logo.svg alt="logo"></a>
          </div>

          <div id="headMenu" class="headerNav">
            <button type="button" id="closeHeadMenu" class="navCloseBtn"><img src="../../_static/img/close-icon.svg" alt="Close"></button>
             <ul class="nav">
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/community>Community</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/download>Download</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/vta>VTA</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/blog>Blog</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvm.apache.org/docs>Docs</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvmconf.org>Conference</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://github.com/apache/tvm/>Github</a>
                </li>
                <li class="nav-item">
                   <a class="nav-link" href=https://tvmchinese.github.io/declaration_zh_CN.html>About-Translators</a>
                </li>
             </ul>
               <div class="responsivetlcdropdown">
                 <button type="button" class="btn-link">
                   ASF
                 </button>
                 <ul>
                     <li>
                       <a href=https://apache.org/>Apache Homepage</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/licenses/>License</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/security/>Security</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/thanks.html>Thanks</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/events/current-event>Events</a>
                     </li>
                     <li>
                       <a href=https://www.zhihu.com/column/c_1429578595417563136>Zhihu</a>
                     </li>
                 </ul>
               </div>
          </div>
            <div class="responsiveMenuIcon">
              <button type="button" id="menuBtn" class="btn-menu"><img src="../../_static/img/menu-icon.svg" alt="Menu Icon"></button>
            </div>

            <div class="tlcDropdown">
              <div class="dropdown">
                <button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  ASF
                </button>
                <div class="dropdown-menu dropdown-menu-right">
                  <ul>
                     <li>
                       <a href=https://apache.org/>Apache Homepage</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/licenses/>License</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/sponsorship.html>Sponsorship</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/security/>Security</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/foundation/thanks.html>Thanks</a>
                     </li>
                     <li>
                       <a href=https://www.apache.org/events/current-event>Events</a>
                     </li>
                     <li>
                       <a href=https://www.zhihu.com/column/c_1429578595417563136>Zhihu</a>
                     </li>
                  </ul>
                </div>
              </div>
          </div>
       </div>
    </div>
 </header>
 
    <nav data-toggle="wy-nav-shift" class="wy-nav-side fixed">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../index.html">
          

          
            
            <img src="../../_static/tvm-logo-small.png" class="logo" alt="Logo"/>
          
          </a>

          
            
            
                <div class="version">
                  0.8.dev1982
                </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption" role="heading"><span class="caption-text">如何开始</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../install/index.html">安装 TVM</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../contribute/index.html">贡献者指南</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">用户引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../tutorial/index.html">User Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../how_to/index.html">How To Guides</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">开发者引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../dev/tutorial/index.html">Developer Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dev/how_to/how_to.html">开发者指南</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">架构指南</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../arch/index.html">Design and Architecture</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">主题引导</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../topic/microtvm/index.html">microTVM：裸机使用TVM</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../topic/vta/index.html">VTA: Versatile Tensor Accelerator</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">参考指南</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="current reference internal" href="#">语言参考</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#introduction-to-relay">Relay简介</a><ul>
<li class="toctree-l3"><a class="reference internal" href="relay_expr.html">Expressions in Relay</a></li>
<li class="toctree-l3"><a class="reference internal" href="relay_type.html">Relay 系统类型</a></li>
<li class="toctree-l3"><a class="reference internal" href="relay_adt.html">Algebraic Data Types in Relay</a></li>
<li class="toctree-l3"><a class="reference internal" href="relay_op.html">Relay 基础张量算子</a></li>
<li class="toctree-l3"><a class="reference internal" href="relay_pattern.html">Pattern Matching in Relay</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#hybrid-script">混合式脚本</a><ul>
<li class="toctree-l3"><a class="reference internal" href="hybrid_script.html">Hybrid Frontend Language Reference</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../api/python/index.html">Python API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api/links.html">Other APIs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../publications.html">Publications</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../genindex.html">索引</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
      
      <nav class="wy-nav-top" aria-label="top navigation" data-toggle="wy-nav-top">
        
            <div class="togglemenu">

            </div>
            <div class="nav-content">
              <!-- tvm -->
              Table of content
            </div>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        

          




















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../index.html">Docs</a> <span class="br-arrow">></span></li>
        
      <li>语言参考</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../../_sources/reference/langref/index.rst.txt" rel="nofollow"> <img src="../../_static//img/source.svg" alt="viewsource"/></a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="language-reference">
<h1>语言参考<a class="headerlink" href="#language-reference" title="永久链接至标题">¶</a></h1>
<p>该文档提供了TVM栈中关于嵌入式语言与中间表示的参考。</p>
<div class="section" id="introduction-to-relay">
<h2>Relay简介<a class="headerlink" href="#introduction-to-relay" title="永久链接至标题">¶</a></h2>
<p>Relay是一种函数式的、可微分编程语言。它被设计用于机器学习系统里一种有效的中间表达方式。Relay支持代数数据类型、闭包、控制流与递归。这些特点允许Relay能比基于计算图的IR直接表示更加复杂的模型。对于一些在参数形状上有复杂要求的算子，为了能对其进行形状分析，Relay用基于依赖类型中的一种，即*type relations*来处理这一问题。</p>
<p>Relay可以根据设计进行扩展，使其对机器学习的研究者及从业者十分友好。他们可以使用Relay简便地进行大规模程序的转换与优化。</p>
<p>以下的页面分别描述了Relay的语法、类型系统、代数数据类型与运算符。</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="relay_expr.html">Expressions in Relay</a><ul>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#dataflow-and-control-fragments">Dataflow and Control Fragments</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#variables">变量</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#functions">Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#operators">Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#adt-constructors">ADT Constructors</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#call">Call</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#module-and-global-functions">Module and Global Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#constant">Constant</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#tuples">Tuples</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#let-bindings">Let Bindings</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#graph-bindings">Graph Bindings</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#if-then-else">If-Then-Else</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#adt-matching">ADT Matching</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_expr.html#tempexprs">TempExprs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="relay_type.html">Relay 系统类型</a><ul>
<li class="toctree-l2"><a class="reference internal" href="relay_type.html#type">类型</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_type.html#tensor-type">张量类型</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_type.html#tuple-type">元组类型</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_type.html#type-parameter">类型参数</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_type.html#type-constraint">类型约束</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_type.html#function-type">函数类型</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_type.html#type-relation">类型关系</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_type.html#incomplete-type">不完整类型</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_type.html#algebraic-data-types">代数数据类型</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="relay_adt.html">Algebraic Data Types in Relay</a><ul>
<li class="toctree-l2"><a class="reference internal" href="relay_adt.html#defining-and-matching-on-an-adt">Defining and Matching on an ADT</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_adt.html#type-checking-adts-and-polymorphism">Type-Checking ADTs and Polymorphism</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_adt.html#recursion-with-adts">Recursion with ADTs</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_adt.html#pattern-matching-in-match-expressions">Pattern Matching in Match Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_adt.html#common-adt-uses">Common ADT Uses</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_adt.html#implementing-neural-nets-using-adts">Implementing Neural Nets Using ADTs</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="relay_op.html">Relay 基础张量算子</a><ul>
<li class="toctree-l2"><a class="reference internal" href="relay_op.html#overview-of-operators">算子概述</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="relay_pattern.html">Pattern Matching in Relay</a><ul>
<li class="toctree-l2"><a class="reference internal" href="relay_pattern.html#pattern-examples">Pattern Examples</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_pattern.html#matching-fuzzy-patterns">Matching Fuzzy Patterns</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_pattern.html#pattern-language-design">Pattern Language Design</a></li>
<li class="toctree-l2"><a class="reference internal" href="relay_pattern.html#applications">Applications</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="section" id="hybrid-script">
<h2>混合式脚本<a class="headerlink" href="#hybrid-script" title="永久链接至标题">¶</a></h2>
<p>以下的页面描述了TVM前端的混合式脚本。其使用模拟程序以支持一些TVM并不正式支持的结构。</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="hybrid_script.html">Hybrid Frontend Language Reference</a><ul>
<li class="toctree-l2"><a class="reference internal" href="hybrid_script.html#overview">Overview</a></li>
<li class="toctree-l2"><a class="reference internal" href="hybrid_script.html#features">特性</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>


           </div>
           
          </div>
          

<footer>

    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="relay_expr.html" class="btn btn-neutral float-right" title="Expressions in Relay" accesskey="n" rel="next">下一个 <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="../../topic/vta/tutorials/autotvm/tune_relay_vta.html" class="btn btn-neutral float-left" title="Auto-tuning a convolutional network on VTA" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> 上一个</a>
      
    </div>

<div id="button" class="backtop"><img src="../../_static//img/right.svg" alt="backtop"/> </div>
<section class="footerSec">
    <div class="footerHeader">
      <ul class="d-flex align-md-items-center justify-content-between flex-column flex-md-row">
        <li class="copywrite d-flex align-items-center">
          <h5 id="copy-right-info">© 2020 Apache Software Foundation | All right reserved</h5>
        </li>
      </ul>

    </div>

    <ul>
      <li class="footernote">Copyright © 2020 The Apache Software Foundation. Apache TVM, Apache, the Apache feather, and the Apache TVM project logo are either trademarks or registered trademarks of the Apache Software Foundation.</li>
    </ul>

</section>
</footer>
        </div>
      </div>

    </section>

  </div>
  

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

  </body>
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
    <!-- Theme Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-75982049-2', 'auto');
    ga('send', 'pageview');
    </script>

    
   

</body>
</html>